<template>
  <div class="hello" id="parent">
    <h1>{{ msg }}</h1>
    <h2>Essential Links</h2>
    <input type="text" ref="input1"/>
    <p ref="component">this is my component {{price}}</p>
    <child  ref="profile" v-model="price"></child>
    <button @click="changeParentMsgFn()">change string</button>
    <button @click="logstrginFn()">log string</button>
    <button @click="backFn()">back to login page</button>
  </div>
</template>

<script>
import Child from './testcomponent/child';
import Vue from 'vue';
export default {
  name: 'home',
  components: {
    Child
  },
  data () {
    return {
      msg: 'Welcome to Your Vue.js App',
      parentMsg:'this is the parent hello world',
      price: 100,
    }
  },
  methods:{
        backFn:function(){
          this.$router.push({name: 'login'});
        },
        changeParentMsgFn(){
          this.parentMsg  = 'changed string';
        },
        logstrginFn(){
          console.log('parent',this.price );
          var parent = new Vue({ el: '#parent' });
          // 访问子组件实例
          var child = parent.$refs.profile;
          this.$refs.input1.value ="22";
          console.log(parent,parent.$refs);
        }
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  display: inline-block;
  margin: 0 10px;
}

a {
  color: #42b983;
}
</style>
